#include "TcpServer.hpp"
#include "NetCal.hpp"
#include <iostream>
#include <memory>
#include "Daemon.h"

int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        std::cerr << "格式输入方式: ./tcpServer port" << std::endl;
        return 1;
    }

    uint16_t port = std::stoi(argv[1]);

    Daemon(1, 1);
    
    ENABLE_FILE_LOG_STRATEGY();

    // 1. 应用层
    std::unique_ptr<NetCal> cal = std::make_unique<NetCal>();
    
    // 2. 协议层
    std::unique_ptr<Protocol> protocol = std::make_unique<Protocol>([&cal](Request& req)->Response{
        return cal->cal(req);
    });

    // 3. 服务器层
    std::unique_ptr<TcpServer> server = std::make_unique<TcpServer>(port, 
        [&protocol](std::shared_ptr<Socket> sock, const InetAddr& client)->void
        {
            protocol->getRequest(sock, client);
        }
    );
    
    server->start();
    
    return 0;
}
